package com.euond.permission.service.impl;

import com.euond.common.core.service.impl.BaseServiceImpl;
import com.euond.permission.dto.UserRoleResourceDto;
import com.euond.permission.entities.Role;
import com.euond.permission.mapper.RoleMapper;
import com.euond.permission.service.RoleResourceService;
import com.euond.permission.service.RoleService;
import com.euond.permission.service.UserRoleService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

/**
 * Created by user on 2017/7/14.
 */
@Service
public class RoleServiceImpl extends BaseServiceImpl<RoleMapper,Role> implements RoleService {

    @Autowired
    private UserRoleService userRoleService;

    @Autowired
    private RoleResourceService roleResourceService;

    @Autowired
    private RoleMapper roleMapper;


    /**
     * 按角色批量增加用户角色、角色资源关系
     * @param userRoleResourceDto
     * @return
     */
    @Override
    @Transactional
    public void addUserRoleResource(UserRoleResourceDto userRoleResourceDto) {
        if(userRoleResourceDto!=null){
            if(userRoleResourceDto.getUserRoleList()!=null){
                userRoleService.deleteUserRoleByRoleId(userRoleResourceDto.getRoleId());
                userRoleService.insertBatch(userRoleResourceDto.getUserRoleList());
            }
            if(userRoleResourceDto.getRoleResourceList()!=null){
                roleResourceService.deleteRoleResourceByRoleId(userRoleResourceDto.getRoleId());
                roleResourceService.insertBatch(userRoleResourceDto.getRoleResourceList());
            }
        }
    }

}
